﻿using System;
using System.IO;
using System.Web.Mvc;

namespace WeiSha.Core
{
	// Token: 0x02000030 RID: 48
	public class TemplateView : IView
	{
		// Token: 0x060001BF RID: 447 RVA: 0x0000CCD0 File Offset: 0x0000AED0
		public void Render(ViewContext viewContext, TextWriter writer)
		{
			bool flag = true;
			bool flag2 = !Server.IsLocalIP;
			if (flag2)
			{
				bool flag3 = "SQLite".Equals(Database.DbType, StringComparison.CurrentCultureIgnoreCase);
				if (flag3)
				{
					bool flag4 = App.Stage == AppStageEnum.Trial;
					if (flag4)
					{
						bool flag5 = Server.InitDateTime < DateTime.Now.AddDays((double)(-(double)App.Span));
						if (flag5)
						{
							flag = false;
						}
					}
				}
				else
				{
					int num = ((App.Span > 30 || App.Span <= 0) ? 30 : App.Span);
					bool isLicense = License.Value.IsLicense;
					if (isLicense)
					{
						int limitCount = License.Value.GetLimitCount("Accounts");
						int num2 = Database.TableCount("Accounts");
						bool flag6 = limitCount > 0 && limitCount < num2;
						if (flag6)
						{
							flag = false;
						}
					}
					else
					{
						bool flag7 = Server.InitDateTime < DateTime.Now.AddDays((double)(-(double)num));
						if (flag7)
						{
							flag = false;
						}
					}
				}
				bool flag8 = !flag;
				if (flag8)
				{
					viewContext.HttpContext.Response.Redirect("/license/" + new Random().Next().ToString());
					return;
				}
			}
			string text = string.Empty;
			bool isCache = Template.IsCache;
			if (isCache)
			{
				text = TemplateDocument.FromFileCache(viewContext);
			}
			else
			{
				text = TemplateDocument.FromFile(viewContext);
			}
			writer.Write(text);
		}
	}
}
